package edu.arizona.sista.learn.model.holding;

import java.util.List;
import java.util.ArrayList;

public class SpatialThing {
	private static int LAST_ASSIGNED_ID = 0;
	
	protected int _id;
	public String _label;
	public List<float[]> _coordinate;
	public List<int[]> _dimension;
	
	public SpatialThing(String label){
		this(LAST_ASSIGNED_ID + 1, label);
		LAST_ASSIGNED_ID++;
	}
	
	public SpatialThing(int id, String label) {
		_id = id;
		_label = label;
		_coordinate = new ArrayList<float[]>();
		_dimension = new ArrayList<int[]>();
	}

	public float[] getCoordinate(int i) {
		return _coordinate.get(i);
	}

	public int[] getDimension(int i) {
		return _dimension.get(i);
	}
	
	public void addCoordinate(float[] coordinate) {
		_coordinate.add(coordinate);
	}
	
	public void addDimension(int[] dimensions) {
		_dimension.add(dimensions);
	}
	
	public int frames() {
		return _coordinate.size();
	}
	
	@Override
	public String toString() {
		return "isa(" + getVariableName() + ", SpatialThing)\n";
	}

	@Override
	public boolean equals(java.lang.Object obj) {
		return ((SpatialThing) obj)._id == _id;
	}
	
	public String getLabel() {
		return _label;
	}

	public String getVariableName() {
		return _label.toLowerCase() + "_" + _id;
	}

	public List<float[]> getCoordinates() {
		return _coordinate;
	}
	
	public void setCoordinates(List<float[]> coordinates) {
		_coordinate = coordinates;
	}

	public double area() {
		double result = 0;
		for(int[] d: _dimension) result += d[0] * d[1];
		return result / _dimension.size();
	}
	
}
